﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RoboZip
{
    public class RoboZipCore
    {
        private List<Job> jobList = new List<Job>();
        private ArgumentParser argumentParser = new ArgumentParser();
        private Job job;

        public RoboZipCore()
        {
            // ToDo: Initialize with Zip, log4net...
        }

        public void CreateJob(string[] args)
        {
            job = new Job();
            argumentParser.ParseArguments( ref job, args);
            if (job.ErrorNumber != ErrorNumber.NoError)
            {
                Console.WriteLine("No jab added.");
                Console.WriteLine("");
                return;
            }
            else
            {
                jobList.Add(job);
            }
        }

        public int JobCount
        {
            get
            {
                return jobList.Count();
            } 
        }

        public void ReportJobs()
        {
            try
            {
                Console.WriteLine("Job count: " + jobList.Count().ToString());
                foreach (Job job in jobList)
                {
                    WiteJobProperties(job);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void WiteJobProperties(Job job)
        {
            Console.WriteLine("GUID: " + job.GUID);
            Console.WriteLine("Execution count: " + job.ExecutionCounter);
            Console.WriteLine("Source: " + job.SourcePath);
            Console.WriteLine("Destination: " + job.DestinationPath);
            Console.WriteLine("Files:");
            foreach (var item in job.FileList)
            {
                Console.WriteLine(" - " + item);
            }
            Console.WriteLine("/FNP: " + job.FileNamePattern);
            Console.WriteLine("/START: " + job.Start.ToString());
            Console.WriteLine("/MP: " + job.MonitoringPeriod);
            Console.WriteLine("/UD: " + job.UpdateDestination.ToString());
            Console.WriteLine("/DS: " + job.DeleteSource.ToString());
            Console.WriteLine("");
        }

        // ToDo: Dispose
    }

}
